package com.neu.fenli2023623.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.fenli2023623.dto.HealthEncyclopediaDto;
import com.neu.fenli2023623.dto.HospitalnavigationDto;
import com.neu.fenli2023623.entity.HealthEncyclopedia;
import com.neu.fenli2023623.entity.Hospitalnavigation;
import com.neu.fenli2023623.service.HospitalnavigationService;
import com.neu.fenli2023623.util.ResultVo;
import com.neu.fenli2023623.vo.DoctorVo;
import com.neu.fenli2023623.vo.HospitalnavigationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hospital")
public class HospitalnavigationController {

    @Autowired
    private HospitalnavigationService hospitalnavigationService;

    @RequestMapping("quaryallhospital")
    public ResultVo quaryall(@RequestBody HospitalnavigationDto hospitalnavigationDto){
        PageHelper.startPage(hospitalnavigationDto.getCurrentPage(),hospitalnavigationDto.getPageSize(),true);
        List<HospitalnavigationVo> hospitalnavigationList = hospitalnavigationService.quaryall();
        PageInfo<HospitalnavigationVo> pageInfo = new PageInfo<>(hospitalnavigationList);
        return ResultVo.ok().data("hospitallist1",hospitalnavigationList).data("total",pageInfo.getTotal());
    }

    @RequestMapping("addHospital")
    public ResultVo addHealth(@RequestBody HospitalnavigationDto record){
        int i = hospitalnavigationService.addHospital(record);
        if(i>0){
            return ResultVo.ok("添加成功");
        }else {
            return ResultVo.error("添加失败");
        }
    }//添加

    @DeleteMapping("{id}")
    public ResultVo deleteHealth(@PathVariable("id") Long id){
        int i = hospitalnavigationService.deleteById(id);
        if (i > 0) {
            return ResultVo.ok("删除成功");
        } else {
            return ResultVo.error("删除失败");
        }
    }//删除

    @PostMapping("{name}")
    public ResultVo selectByName(@PathVariable("name") String name){
        List<Hospitalnavigation> hospitalnavigationList = hospitalnavigationService.selectByName(name);
        if(hospitalnavigationList!=null){
            return ResultVo.ok().data("hospitallist",hospitalnavigationList);
        }else {
            return ResultVo.error("查询失败");
        }
    }//查询

    @RequestMapping("{id}")
    public ResultVo selectById(@PathVariable("id") Long id){
        Hospitalnavigation hospitalnavigation = hospitalnavigationService.selectById(id);
        return ResultVo.ok().data("hospital",hospitalnavigation);
    }
    @RequestMapping("updateHospital")
    public ResultVo update(@RequestBody HospitalnavigationDto record){
        int i = hospitalnavigationService.updateHospital(record);
        if (i>0) {
            return ResultVo.ok("更新成功");
        }else {
            return ResultVo.error("更新失败");
        }
    }//更新

}
